import { inject, injectable } from 'inversify';
import { RoleListModel } from '../models/role.list.model.ts';
import { UsersRolesRepository } from '../data/users.roles.repository.ts';

@injectable()
export class GetPermissionListUseCase {
  constructor(
    @inject(RoleListModel) private roleListModel: RoleListModel,
    @inject(UsersRolesRepository) private rolesRepository: UsersRolesRepository,
  ) {}

  async execute() {
    if (this.roleListModel.permissionList.length) {
      return;
    }

    try {
      this.roleListModel.permissionLoading = true;
      const { data } = await this.rolesRepository.getPermissionList();
      this.roleListModel.permissionList = data;
    } finally {
      this.roleListModel.permissionLoading = false;
    }
  }
}
